package com.company;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @date : 2021-12-13 下午10:43
 * Java运行时环境的用途
 */

public class P011_Runtime {
    public static void main(String[] args) {
        Runtime runtime = Runtime.getRuntime();
        System.out.println("处理器核数：" + runtime.availableProcessors());
        System.out.println("GC之前最大内存：" + runtime.maxMemory() / 1024 / 1204 + "M");
        System.out.println("GC之前总空闲内存：" + runtime.totalMemory() / 1024 / 1204 + "M");
        System.out.println("GC之前空闲内存：" + runtime.freeMemory() / 1024 / 1204 + "M");
        runtime.gc();
        System.out.println("GC之后空闲内存：" + runtime.freeMemory() / 1024 / 1204+ "M");
        executeLs(runtime);
        runtime.exit(0);
        System.out.println(1);
    }

    public static void executeLs(Runtime runtime) {
        System.out.println("---start---");
        try {
            Process ls = runtime.exec("ls");
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(ls.getInputStream()));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.println("----end----");
    }

}
